<style lang="less">
    @import '../../styles/common.less';
    @import '../tables/components/table.less';
</style>
<template>
    <div>
        <!--<form action="" style="margin: 5px 0">-->
            <!--<Input v-model="name" icon="search"  placeholder="根据用户名查找" @on-click="searchName" style="width: 200px;margin-right: 3px;"></Input>-->
            <!--<Input v-model="phone" icon="search" placeholder="根据手机号查找" @on-click="searchPhone" style="width: 200px"></Input>-->
        <!--</form>-->
        <Table :loading="loading" refs="table1" @on-selection-change="changeNum":data="Message" :columns="columnsList"></Table>

        <Modal
                v-model="modal2"
                title="修改"
        >
            <Form ref="formValidate" :model="changeInner"  :rules="ruleValidate" :label-width="100">
                <Row :gutter="16">
                    <Col span="12">
                    <FormItem label="积分修改" prop="usd">
                        <Input v-model="changeInner.usd"   style="margin-right: 3px;"></Input>
                    </FormItem>
                    </Col>
                </Row>
            </Form>
            <div slot="footer">
                <Button type="primary" @click="sub('formValidate')">保存</Button>
            </div>
        </Modal>
        <Page :total="pageNum" :page-size="pageSize"  style="text-align: center;margin-top: 15px;"  @on-change="pageChange"></Page>
    </div>
</template>
<script>
    import $http from '../../utils/axiosWrap'
    import canEditTable from '../tables/components/canEditTable.vue'
    import Cookies from 'js-cookie';

    export default {
        data() {
            return {
                loading: true,
                Message:[],
                admin:true,
                modal1:false,
                modal2:false,
                userListInner:{},
                changeInner:{
                    id:'',
                    eth:'',
                    usd:'',
                },
                columnsList: [
                    {
                        title: '序号',
                        width: 80,
                        align: 'center',
                        render: (h, params) => {
                            return  params.index + (this.initPage- 1) * this.pageSize + 1
                        }
                    },
                    {
                        title: '用户名',
                        align: 'center',
                        key: 'name',
                        editable: true
                    },
                    {
                        title: '手机号',
                        align: 'center',
                        key: 'phone',
                        editable: true
                    },
                    {
                        title: '积分',
                        align: 'center',
                        key: 'totalIntegral',
                        editable: true
                    },
                    {
                        title: '变动前积分',
                        align: 'center',
                        key: 'oldIntegral',
                        editable: true
                    },
                    {
                        title: '创建时间',
                        align: 'center',
                        editable: true,
                        width:160,
                        render: (h, params) => {
                            if(params.row.creatTime){
                                return params.row.creatTime.replace(/\T/g, ' ').substring(0,19)
                            }else{
                                return ''
                            }
                        }
                    },
                    {
                        title: '修改时间',
                        align: 'center',
                        width:160,
                        render: (h, params) => {
                            if(params.row.updateTime){
                                return params.row.updateTime.replace(/\T/g, ' ').substring(0,19)
                            }else{
                                return ''
                            }
                        }
                    },
                    {
                        title: '操作',
                        align: 'center',
                        width: 170,
                        render: (h, params) => {
                            if( Cookies.get('access') == 0){
                                return h('div', [

                                    h('Button', {
                                        props: {
                                            type: 'primary',
                                            size: 'small'
                                        },
                                        style: {
                                            marginRight: '5px'
                                        },
                                        on: {
                                            click: () => {
                                                this.change(params)
                                            }
                                        }
                                    }, '编辑')
                                ]);
                            }else{
                                return h('div', [
                                    h('Button', {
                                        props: {
                                            type: 'success',
                                            size: 'small'
                                        },
                                        style: {
                                            marginRight: '5px'
                                        },
                                        on: {
                                            click: () => {
                                                this.info(params)
                                            }
                                        }
                                    }, '查看')
                                ]);
                            }
                        }
                    }
                ],
                name: '',
                phone: '',
                ruleValidate: {
                    usd: [
                        { required: true, message: '积分不得为空', trigger: 'blur' }
                    ]
                },
                pageNum:1,
                pageSize:10,
                initPage:1
            }
        },
        created: function () {
            this.load()
        },
        methods: {
            pageChange(index){
                this.initPage = index
                this.loading = true
                this.load ()
            },
            load (){
                let _this = this
                let params = new URLSearchParams()
                params.append('pno',_this.initPage)
                $http.post('/backgroundUser/listUserIntegral',params).then(function (res) {
                    if(res.suc){
                        _this.Message = res.result.list
                        _this.pageNum = res.result.totalIntegral
                    }else{
                        if(res.msg == "请先登录"){
                            _this.$Message.error('请重新登录！');
                        }else{
                            _this.$Message.error(res.msg);
                        }
                    }
                    _this.loading = false
                })
            },
            changeNum (val){
                console.log(val)
            },
            change(val){
                this.modal2 = true
                this.changeInner.usd = ''
                this.changeInner.id=val.row.userId
                this.changeInner.usd = val.row.totalIntegral
                console.log(val)
            },
            sub(name){
                let _this = this
                if(_this.changeInner.usd)
                    _this.changeInner.usd += ''
                _this.$refs[name].validate((valid) => {
                    if (valid) {
                            let params = new URLSearchParams()
                            params.append('userId',_this.changeInner.id)
                            params.append('totalIntegral',_this.changeInner.usd)
                            params.append('sysId',Cookies.get('userId'))
                            $http.post('/backgroundUser/insertSysIntegal',params).then(function (res) {
                                if(res.suc){
                                    _this.load()
                                    _this.modal2 = false
                                    _this.$Message.info('修改成功');
                                }else{
                                    _this.$Message.info('修改失败');
                                }
                            })
                    } else {
                        _this.$Message.error('信息填写有误!')
                    }
                })
            }
        }
    }
</script>
<style>
    .userListInfo{
        display: inline-block;
        width: 120px;
    }
    .userListInfoWrap p{
        line-height: 26px;
    }
</style>

